package com.lcxw.hxzbapi.dao.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.lcxw.hxzbapi.entity.pojo.CubeDrawRecord;
import com.lcxw.hxzbapi.entity.response.CubeDrawRecordForMem;
import java.util.List;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface CubeDrawRecordMapper extends BaseMapper<CubeDrawRecord> {

    @Select("SELECT `addTime` FROM `ywpd_cubedrawrecord` WHERE userId = #{userId} GROUP BY `addTime`")
    List<String> selectAddTimeGroup(long userId);

    @Select("SELECT userId from `ywpd_cubedrawrecord` GROUP BY userId")
    List<Long> selectAllUserId();

    @Select("SELECT DISTINCT userId from `ywpd_cubedrawrecord` WHERE date_format(NOW(),'%Y%m%d')=date_format(addTime,'%Y%m%d')")
    List<Long> selectTodayUser();


    @Select("SELECT * FROM `ywpd_cubedrawrecord` WHERE userId = #{userId} and date_format(NOW(),'%Y%m%d')=date_format(addTime,'%Y%m%d') ")
    List<CubeDrawRecord> selectTodayListUser(Long userId);

    @Select("SELECT #{giftNum} * (SELECT needCoin FROM ywpd_gift WHERE id = #{giftId})")
    int getOneGiftCount(@Param("giftNum") int giftNum, @Param("giftId") int giftId);

    @Select("select a.userName,a.`nickName`,b.`drawType`,b.`addTime`,c.`giftName`,c.`giftIcon`,b.`giftNum` from (ywpd_member a inner join ywpd_cubedrawrecord b  on a.`userId` = b.userId ) inner join ywpd_gift c on b.`giftId` = c.`id` Limit #{pageNum},#{pageSize};")
    List<CubeDrawRecordForMem> getRecords(@Param("pageNum") int pageNum,
        @Param("pageSize") int pageSize);

    @Select("SELECT DISTINCT d.nickName,a.userId,a.addTime,a.drawType FROM ywpd_cubedrawrecord a LEFT JOIN ywpd_cube b on a.giftId=b.giftId LEFT JOIN ywpd_gift c on a.giftId=c.id LEFT JOIN ywpd_member d on a.userId=d.userId WHERE c.needcoin>=99 and b.type=#{type}  order BY a.addTime desc limit 20")
    List<CubeDrawRecordForMem> getNotices(@Param("type") String type);

    @Select("SELECT DISTINCT b.giftName,b.giftIcon,a.giftNum FROM ywpd_cubedrawrecord a LEFT JOIN ywpd_gift b  on a.giftId=b.id  where  a.addTime=#{addTime} and a.userId=#{userId} order by b.needcoin desc")
    List<CubeDrawRecordForMem> getLists(@Param("addTime") String addTime,@Param("userId") String userId);

}
